#ifndef QTAV_AVTHREAD_P_H
#define QTAV_AVTHREAD_P_H

#include <QtCore/QMutex>
#include <QtCore/QMutexLocker>
#include <QtCore/QWaitCondition>

#include <QtAV/Packet.h>
#include <QtAV/QtAV_Global.h>

class QRunnable;
namespace QtAV {

const double kSyncThreshold = 0.2; // 200 ms

class AVDecoder;
class AVOutput;
class AVClock;
class Filter;
class FilterContext;
class Statistics;
class OutputSet;
class Q_AV_EXPORT AVThreadPrivate : public DPtrPrivate<AVThread>
{
public:
    AVThreadPrivate():
        paused(false)
      , next_pause(false)
      , demux_end(false)
      , stop(false)
      , clock(0)
      , dec(0)
      , outputSet(0)
      , writer(0)
      , delay(0)
      , filter_context(0)
      , statistics(0)
      , ready(false)
    {
    }
    //DO NOT delete dec and writer. We do not own them
    virtual ~AVThreadPrivate();

    bool paused, next_pause;
    bool demux_end;
    volatile bool stop; //true when packets is empty and demux is end.
    AVClock *clock;
    PacketQueue packets;
    AVDecoder *dec;
    OutputSet *outputSet;
    AVOutput *writer;
    QMutex mutex;
    QWaitCondition cond; //pause
    qreal delay;
    FilterContext *filter_context;//TODO: use own smart ptr. QSharedPointer "=" is ugly
    QList<Filter*> filters;
    Statistics *statistics; //not obj. Statistics is unique for the player, which is in AVPlayer
    QList<AVOutput*> update_outputs;
    QList<QRunnable*> tasks;
    QWaitCondition ready_cond;
    QMutex ready_mutex;
    bool ready;
};

} //namespace QtAV
#endif // QTAV_AVTHREAD_P_H
